#pragma once
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include "cppjieba/include/cppjieba/Jieba.hpp"

class Util
{
public:
    static bool ReadFile(const std::string& file_path, std::string* out)
    {
        std::ifstream ifs(file_path, std::ios::in);
        if (!ifs.is_open()) {
            std::cerr << "open file " << file_path << " failed" << std::endl;
            return false;
        }
        std::string line;
        while (getline(ifs, line)) { // getline返回值是ostream&，输出流对象重载了真假的判断
            *out += line;
        }
        ifs.close();
        return true;
    }

    static void CutString(const std::string& src, std::vector<std::string>* out, std::string& sep)
    {
        // boost spilt
        boost::split(*out, src, boost::is_any_of(sep), boost::token_compress_off);  // 按sep切分
    }

};

const char* DICT_PATH = "cppjieba/dict/jieba.dict.utf8";
const char* HMM_PATH = "cppjieba/dict/hmm_model.utf8";
const char* USER_DICT_PATH = "cppjieba/dict/user.dict.utf8";
const char* IDF_PATH = "cppjieba/dict/idf.utf8";
const char* STOP_WORD_PATH = "cppjieba/dict/stop_words.utf8";

class Jieba
{
private:
    static cppjieba::Jieba _jieba;
public:
    static void SpiltPhrase(const std::string& src, std::vector<std::string>* out)
    {
        _jieba.CutForSearch(src, *out);
    }

};
cppjieba::Jieba Jieba::_jieba(DICT_PATH, HMM_PATH, USER_DICT_PATH, IDF_PATH, STOP_WORD_PATH);
